package model

import "gorm.io/gorm"

// 销售员
type Seller struct {
	Id          int    `gorm:"column:id;primary_key;AUTO_INCREMENT" form:"id" json:"id"`
	UserId      int    `gorm:"column:user_id" form:"user_id" json:"userId"`
	SellerName  string `gorm:"column:seller_name" form:"sellerName" json:"sellerName"`
	SellerPhone string `gorm:"column:seller_phone" form:"sellerPhone" json:"sellerPhone"`
}

type GoodsSales struct {
	Id               int    `gorm:"column:id;primary_key;AUTO_INCREMENT" form:"id" json:"id"`
	UserId           int    `gorm:"column:user_id" form:"user_id" json:"userId"`
	CarId            int    `gorm:"column:car_id" form:"car_id" json:"carId"`
	ProductType      string `gorm:"column:type" form:"type" json:"type"`
	ProductCode      string `gorm:"column:code" form:"code" json:"code"`
	ProductName      string `gorm:"column:name" form:"name" json:"name"`
	SalesNumber      int    `gorm:"column:sales_number" form:"sales_number" json:"salesNumber"`
	SalesArea        string `gorm:"column:sales_area" form:"sales_area" json:"salesArea"`
	UnitPrice        string `gorm:"column:unit_price" form:"unit_price" json:"unitPrice"`
	NumberPlate      string `gorm:"column:number_plate" form:"number_plate" json:"numberPlate"`
	ParkingLocation  string `gorm:"column:parking_location" form:"parking_location" json:"parkingLocation"`
	LogisticsCompany string `gorm:"column:logistics_company" form:"logistics_company" json:"logisticsCompany"`
	DriverPhone      string `gorm:"column:driver_phone" form:"driver_phone" json:"driverPhone"`
	Supplier         string `gorm:"column:supplier" form:"supplier" json:"supplier"`
	Customer         string `gorm:"column:customer_phone" form:"customer_phone" json:"customer"`
	CustomerPhone    string `gorm:"column:customer_phone" form:"customer_phone" json:"customerPhone"`
	Date             string `gorm:"column:date" form:"date" json:"date"`
}

/**
 * 公司销售记录
 */
type CompanySalesRecord struct {
	gorm.Model
	UserId             int                  `gorm:"column:user_id" form:"userId" json:"userId"`
	ProductType        string               `gorm:"column:product_type" form:"productType" json:"productType"`             //产品类型
	Date               string               `gorm:"column:date" form:"date" json:"date"`                                   //销售日期
	Seller             string               `gorm:"column:seller" form:"seller" json:"seller"`                             //销售员
	TotalPrice         float64              `gorm:"column:total_price" form:"totalPrice" json:"totalPrice"`                //商品总价
	PendingPayment     float64              `gorm:"column:pending_payment" form:"pendingPayment" json:"pendingPayment"`    //剩余货款
	DiscountedPrice    float64              `gorm:"column:discounted_price" form:"discountedPrice" json:"discountedPrice"` //优惠金额
	CustomerId         uint                 `gorm:"customer_id" form:"customerId" json:"customerId"`                       //顾客id
	CustomerName       string               `gorm:"customer_name"  form:"customerName" json:"customerName,omitempty"`
	CustomerPhone      string               `gorm:"customer_phone"  form:"customerPhone" json:"customerPhone,omitempty"`
	Customer           []Customer           `gorm:"many2many:sales_customer" json:"customer,omitempty"` //客户信息
	CarId              int                  `gorm:"-" form:"carId" json:"carId,omitempty"`
	CarArea            string               `gorm:"-"  form:"carArea" json:"carArea,omitempty"`
	CarPlate           string               `gorm:"-"  form:"carPlate" json:"carPlate,omitempty"`
	CarInfo            []CarInfo            `gorm:"many2many:sales_car" json:"carInfo,omitempty"`      //车辆信息
	ProductSalesRecord []ProductSalesRecord `gorm:"many2many:sales_product" json:"productSalesRecord"` //商品详情
	BankFlow           []BankFlow           `gorm:"many2many:sales_bank" json:"bankFlow"`              //银行流水
}

type ProductSalesRecord struct {
	gorm.Model
	UserId               int         `gorm:"column:user_id" form:"userId" json:"userId"`
	CompanySalesRecordId int         `gorm:"company_sales_record_id" form:"companySalesRecordId" json:"companySalesRecordId"` //销售id
	CustomerId           uint        `gorm:"customer_id" form:"customerId" json:"customerId"`                                 //顾客id
	ProductId            int         `gorm:"product_id" form:"productId" json:"productId"`                                    //商品id
	Product              string      `gorm:"product" form:"product" json:"product"`                                           //商品
	InventoryNumber      int         `gorm:"-" form:"inventoryNumber" json:"inventoryNumber"`                                 //库存件数
	InventoryWeight      float64     `gorm:"-" form:"InventoryWeight" json:"InventoryWeight"`                                 //库存重量
	SalesNumber          int         `gorm:"column:sales_number" form:"salesNumber" json:"salesNumber"`                       //销售数量
	SalesWeight          float64     `gorm:"column:sales_weight" form:"salesWeight" json:"salesWeight"`                       //销售重量
	SalesPrice           float64     `gorm:"column:sales_price" form:"salesPrice" json:"salesPrice"`                          //销售单价
	TotalPrice           float64     `gorm:"column:total_price" form:"totalPrice" json:"totalPrice"`                          //销售总价
	Date                 string      `gorm:"column:date" form:"date" json:"date"`
	InventoryList        []Inventory `gorm:"many2many:sales_inventory_record" json:"inventoryList"`
	//品名
}

type CompanySalesResult struct {
	Id                 uint                 `json:"id"`
	ProductType        string               `json:"productType"`                          //产品类型
	Customer           string               `json:"customer"`                             //客户
	CustomerPhone      string               `json:"customerPhone"`                        //客户电话
	Date               string               `json:"date"`                                 //销售日期
	Seller             string               `json:"seller"`                               //销售员
	SalesArea          string               `json:"salesArea"`                            //销售地
	ProductSalesResult []ProductSalesResult `gorm:"embedded" json:"ProductSalesInfoList"` //商品详情
}
type ProductSalesResult struct {
	Id            uint    `json:"id"`
	Product       string  `json:"product"`       //产品
	ProductUnit   string  `json:"productUnit"`   //产品单位
	Specification string  `json:"specification"` //规格
	SalesNumber   int     `json:"salesNumber"`   //销售数量
	SalesWeight   float64 `json:"salesWeight"`   //销售重量
	SalesPrice    float64 `json:"salesPrice"`    //销售单价
	FactoryNo     string  `json:"factoryNo"`     //厂号
	ProductName   string  `json:"productName"`   //品名
	SalesDate     string  `json:"salesDate"`     //品名
}

type ProductFlow struct {
	Id               int     `gorm:"column:id;primary_key;AUTO_INCREMENT" form:"id" json:"id"`
	UserId           int     `gorm:"column:user_id" form:"userId" json:"userId"`
	CarId            uint    `gorm:"column:car_id" form:"carId" json:"carId"`
	Attribute        string  `gorm:"column:attribute" form:"attribute" json:"attribute"` //属性：猪、牛
	ProductId        int     `gorm:"column:product_id" form:"productId" json:"productId"`
	FactoryNo        string  `gorm:"column:factory_no" form:"factoryNo" json:"factoryNo" binding:"required"`
	ProductName      string  `gorm:"column:product_name" form:"productName" json:"productName" binding:"required"`
	Number           float32 `gorm:"column:number" form:"number" json:"number"`                                //数量
	SalesArea        string  `gorm:"column:sales_area" form:"salesArea" json:"salesArea"`                      //销售地
	ParkingSpace     string  `gorm:"column:parking_space" form:"parkingSpace" json:"position"`                 //停车位
	PlateNumber      string  `gorm:"column:plate_number" form:"plateNumber" json:"plateNumber"`                //车牌号
	LogisticsCompany string  `gorm:"column:logistics_company" form:"logisticsCompany" json:"logisticsCompany"` //物流公司
	DriverPhone      string  `gorm:"column:driver_phone" form:"driverPhone" json:"driverPhone"`                //电话
	Date             string  `gorm:"column:date" form:"date" json:"date"`                                      //销售日期
	Time             int64   `gorm:"-" form:"time" json:"time"`
	Customer         string  `gorm:"column:customer" form:"customer" json:"customer,omitempty"` //顾客
	Supplier         string  `gorm:"column:supplier" form:"supplier" json:"supplier,omitempty"` //上游企业
}

type SalesStatisticsOrder struct {
	gorm.Model
	UserId                 int                      `gorm:"column:user_id" form:"userId" json:"userId"`
	CustomerId             int                      `gorm:"column:customer_id" form:"customerId" json:"customerId"`
	CustomerName           string                   `gorm:"column:customer_name" form:"customerName" json:"customerName"`
	SellerId               int                      `gorm:"column:seller_id" form:"sellerId" json:"sellerId"`
	Date                   string                   `gorm:"column:date" form:"date" json:"date"`
	TotalPrice             float64                  `gorm:"column:total_price" form:"totalPrice" json:"totalPrice"`
	Arrears                float64                  `gorm:"column:arrears" form:"arrears" json:"arrears"`
	DiscountAmount         float64                  `gorm:"column:discount_amount" form:"discountAmount" json:"discountAmount"`
	Remark                 string                   `gorm:"column:remark" form:"remark" json:"remark"`
	SalesStatisticsProduct []SalesStatisticsProduct `gorm:"ForeignKey:SalesOrderId;AssociationForeignKey:Id" format:"salesProductList" json:"salesProductList"`
}

type SalesStatisticsProduct struct {
	gorm.Model
	Date            string  `gorm:"column:date" form:"date" json:"date"`
	SalesOrderId    int     `gorm:"column:sales_order_id" form:"salesOrderId" json:"salesOrderId"`
	CustomerId      int     `gorm:"column:customer_id" form:"customerId" json:"customerId"`
	CustomerName    string  `gorm:"column:customer_name" form:"customerName" json:"customerName"`
	InventoryId     int     `gorm:"column:inventory_id" form:"inventoryId" json:"inventoryId"`
	ProductId       int     `gorm:"column:product_id" form:"productId" json:"productId"`
	FactoryNo       string  `gorm:"column:factory_no" form:"factoryNo" json:"factoryNo"`
	ProductName     string  `gorm:"column:product_name" form:"productName" json:"productName"`
	Specification   string  `gorm:"->" form:"specification" json:"specification"`
	SalesNumber     int     `gorm:"column:sales_number" form:"salesNumber" json:"salesNumber"`
	SalesWeight     float64 `gorm:"column:sales_weight" form:"salesWeight" json:"salesWeight"`
	SalesPrice      float64 `gorm:"column:sales_price" form:"salesPrice" json:"salesPrice"`
	SalesTotalPrice float64 `gorm:"column:sales_total_price" form:"salesTotalPrice" json:"salesTotalPrice"`
	Remark          string  `gorm:"column:remark" form:"remark" json:"remark"`
}
